<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('小说评论列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <input type="hidden" id="userId" th:value="${userId}">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>小说：</label>
                            <input type="text" name="novelId"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:comment:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:comment:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:comment:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:comment:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:comment:remove')}]];
    var prefix = ctx + "system/comment";



    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "小说评论",
            pagination: true,            // 必须显式开启
            pageSize: 10,                // 默认分页大小
            pageList: [10, 25, 50],      // 可选分页大小
            showPageGo: true,            // 显示快速跳转
            showRefresh: true,           // 显示刷新按钮
            sidePagination: "server",
            columns: [{
                checkbox: true
            },
                {
                    field: 'commentId',
                    title: '评论编号',
                    visible: false
                },
                {
                    field: 'index',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index + 1; // 表格的索引从0开始，因此加1
                    }
                },
                {
                    field: 'userName',
                    title: '用户'
                },
                {
                    field: 'novelName',
                    title: '小说'
                },
                {
                    field: 'content',
                    title: '评论内容'
                },
                {
                    field: 'rating',
                    title: '评分'
                },
                {
                    title: '操作人',
                    formatter: function (value, row, index) {
                        // 生成一个 BZ前缀 + 随机四位数字的值即可
                        var randomNum = Math.floor(Math.random() * 9000) + 1000;
                        return 'BZ' + randomNum;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.isAdmin){
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="replyComment(\'' + row.commentId + '\')"><i class="fa fa-commenting"></i>回复</a> ');
                        }
                        if (row.showRemove){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.commentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);




    });

    // 新增回复方法
    // 修改后的回复方法
    function replyComment(commentId) {
        var content = '';
        var modal = layer.prompt({
            title: '回复评论',
            formType: 2, // 多行输入框
            maxlength: 200,
            value: content,
            area: ['500px', '200px']
        }, function(value, index, elem){
            if(value) {
                console.log(value);
                layer.close(index);
                layer.alert("回复成功！");
                // $.operate.submit(prefix + "/reply", "post", {
                //     commentId: commentId,
                //     content: value
                // }, function() {
                //     layer.close(index);
                //     $.table.refresh();
                // });
            }
        });
    }

</script>
</body>
</html>